<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return['basic']=$this->plugin_setting('basic');
$return['pluginset']['ailogo']=tomedia($return['pluginset']['ailogo']);
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'ischat'=>1,'answer <>'=>'NULL');
	$fields=array('id','askmsg','createtime');
	$orderby=array();
	$_RQ['page'] = $_RQ['page'] ? $_RQ['page'] : 1;
	$pindex = max(1, intval($_RQ['page']));
	if(intval($_RQ['num'])){
		$psize = intval($_RQ['num']);
	}else{
		$psize = 10;
	}
	$total='';
	$list=pdo_getslice('jy_aixiaoyi_msglog',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['msgnum']=pdo_count('jy_aixiaoyi_msglog',array('chatid'=>$item['id'],'uniacid'=>$_SESSION['uniacid'],'answer <>'=>'NULL'));
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
		}
	}
	$return['list']=$list?$list:array();
	set_html('title','我的对话');
    //删除chatgpt的无效数据(待定)
    
	exi($return);
}
if($_RQ['op']=='detail'){
	$chatid=intval($_RQ['chatid']);
	$return['item']=pdo_get('jy_aixiaoyi_msglog',array('id'=>$chatid,'uniacid'=>$_SESSION['uniacid']));
	if(!$return['item']){
		exi('指定对话不存在！','error','list');
	}
	$return['member']=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('avatar','nickname'));
	$return['member']['avatar']=tomedia($return['member']['avatar']);
	$return['list']=array();
	set_html('title',$return['item']['askmsg']);
	exi($return);
}